package com.kld.yqyj.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.kld.common.annotation.RepeatSubmit;
import com.kld.common.annotation.Log;
import com.kld.common.core.controller.BaseController;
import com.kld.common.core.domain.PageQuery;
import com.kld.common.core.domain.R;
import com.kld.common.core.validate.AddGroup;
import com.kld.common.core.validate.EditGroup;
import com.kld.common.core.validate.QueryGroup;
import com.kld.common.enums.BusinessType;
import com.kld.common.utils.poi.ExcelUtil;
import com.kld.yqyj.domain.vo.TInjwwDVo;
import com.kld.yqyj.domain.bo.TInjwwDBo;
import com.kld.yqyj.service.ITInjwwDService;
import com.kld.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 注水井生产日报Controller
 *
 * @author bw
 * @date 2024-05-15
 */
@Validated
@Api(value = "注水井生产日报控制器", tags = {"注水井生产日报管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/yqyj/injwwD")
public class TInjwwDController extends BaseController {

    private final ITInjwwDService iTInjwwDService;

    /**
     * 查询注水井生产日报列表
     */
    @ApiOperation("查询注水井生产日报列表")
    @SaCheckPermission("yqyj:injwwD:list")
    @GetMapping("/list")
    public TableDataInfo<TInjwwDVo> list(@Validated(QueryGroup.class) TInjwwDBo bo, PageQuery pageQuery) {
        return iTInjwwDService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出注水井生产日报列表
     */
    @ApiOperation("导出注水井生产日报列表")
    @SaCheckPermission("yqyj:injwwD:export")
    @Log(title = "注水井生产日报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated TInjwwDBo bo, HttpServletResponse response) {
        List<TInjwwDVo> list = iTInjwwDService.queryList(bo);
        ExcelUtil.exportExcel(list, "注水井生产日报", TInjwwDVo.class, response);
    }

    /**
     * 获取注水井生产日报详细信息
     */
    @ApiOperation("获取注水井生产日报详细信息")
    @SaCheckPermission("yqyj:injwwD:query")
    @GetMapping("/{wellId}")
    public R<TInjwwDVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("wellId") String wellId) {
        return R.ok(iTInjwwDService.queryById(wellId));
    }

    /**
     * 新增注水井生产日报
     */
    @ApiOperation("新增注水井生产日报")
    @SaCheckPermission("yqyj:injwwD:add")
    @Log(title = "注水井生产日报", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TInjwwDBo bo) {
        return toAjax(iTInjwwDService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改注水井生产日报
     */
    @ApiOperation("修改注水井生产日报")
    @SaCheckPermission("yqyj:injwwD:edit")
    @Log(title = "注水井生产日报", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TInjwwDBo bo) {
        return toAjax(iTInjwwDService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除注水井生产日报
     */
    @ApiOperation("删除注水井生产日报")
    @SaCheckPermission("yqyj:injwwD:remove")
    @Log(title = "注水井生产日报", businessType = BusinessType.DELETE)
    @DeleteMapping("/{wellIds}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable String[] wellIds) {
        return toAjax(iTInjwwDService.deleteWithValidByIds(Arrays.asList(wellIds), true) ? 1 : 0);
    }
}
